import '../css/startGame.scss'
import '../css/common/header.scss'
import '../css/common/footer.scss'
import "../assets/js/jquery.min.js"
import "../assets/js/jquery.qqFace.js"

if (module.hot) { module.hot.accept() } // 实现热更新

setTimeout(()=>{
    console.log('startGame');
}, 1000);

// 鼠标hvoer显示图片
(function () {
    var $gift = $('.h5-right .hot-game ul li');

    $gift.hover(function () {
        $(this).siblings().removeClass('active');
        $(this).addClass('active');
    })
})();


// 列图展示模块
(function () {
    var $exq = $('.exquisite');
    var num = $exq.find('.exquisite_list ul li').length-3;
    var index = 0;

    $exq.find('.exquisite_prev').click(function () {
        index --;
        index = Math.max(index, 0);
        $exq.find('.exquisite_list ul').stop().animate({left: -(250+23)*index+'px'}, 300, 'linear')
    });
    $exq.find('.exquisite_next').click(function () {
        index ++;
        index = Math.min(index, num);
        $exq.find('.exquisite_list ul').stop().animate({left: -(250+23)*index+'px'}, 300, 'linear')
    });
})();

(function () { // 文本超出隐藏
    var $not = $('.n_w_s');

    var $span = $not.find('.news ul li .right-text .commit span');
    console.log($span);
    for (let i = 0; i < $span.length; i++) {
        textEllipsis($span.get(i), 2, 540);
    }

    function textEllipsis(ele, line, y) {
        if((ele.currentStyle?ele.currentStyle['position']:getComputedStyle(ele)['position']) === "static") ele.style.position = "relative";
        var str = ele.innerText;
        ele.innerHTML = null;
        var lineSum = 1;
        var strIndex = '';
        var topS = 0;
        var topT = 0;
        for (var i = 0; i < str.length; i++) {
            var eSpan = document.createElement('span');
            strIndex = str.substring(i, i+1);
            eSpan.innerText = strIndex;
            ele.appendChild(eSpan);
            topT = eSpan.offsetTop;
            if (topS !== topT) {topS = topT;lineSum ++;}
            if (lineSum === line && eSpan.offsetLeft + eSpan.offsetWidth >= y) {
                ele.innerHTML = null;
                ele.innerText = (str.substring(0, i)).replace(/.{1,3}$/, '...');
                break
            }
            if (lineSum > line) {
                ele.innerHTML = null;
                ele.innerText = (str.substring(0, i)).replace(/.{1,4}$/, '...');
                return
            }
            if (i === str.length - 1) {
                ele.innerHTML = null;
                ele.innerText = str;
            }
        }
    }
})()


// 评论表情
$(function(){

    $('.face-show').qqFace({
        id : 'face-box',
        assign:'input-content',
        path:'../assets/img/arclist/'	//表情存放的路径

    });


});

//查看结果
function replace_em(str){

    str = str.replace(/\</g,'&lt;');

    str = str.replace(/\>/g,'&gt;');

    str = str.replace(/\n/g,'<br/>');

    str = str.replace(/\[em_([0-9]*)\]/g,'<img src="../assets/img/arclist/$1.gif" border="0" />');

    return str;

}
